package ltd.dujiabao.eduservice.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ltd.dujiabao.commonutils.Result;
import ltd.dujiabao.eduservice.entity.subject.PrimarySubject;
import ltd.dujiabao.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author dujiabao
 * @since 2021-04-21
 */
@Api(value = "课程分类管理")
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {
  @Autowired
  EduSubjectService eduSubjectService;

  @ApiOperation("通过excel文件上传课程分类")
  @PostMapping("/import")
  public Result InputInfoByExcel(MultipartFile file) {
    boolean isSuccess = eduSubjectService.saveBatchByExcel(file);
    if (isSuccess) {
      return Result.success();
    } else {
      return Result.failure();
    }
  }

  @ApiOperation("查询课程分类信息，通过树状形式保存")
  @GetMapping("/tree")
  public Result getSubjectsTree() {
    List<PrimarySubject> result = eduSubjectService.getSubjectsTree();
    return Result.success().addData("data", result);
  }

}

